<template>
	<div>
		<router-link 
		tag ="div"
		 to = "/"
		  class="header-abs"
		  v-show="showabs"
		  >
			<span class="iconfont header-abs-back">&#xe624;</span>
		</router-link>
		<div class="header-fixed"
		  v-show="!showabs"
		  :style="opacityStyle"
		  >
			<router-link to = "/">
				<div class="iconfont header-fixed-back">&#xe624;</div>
			</router-link>
			景点详情
		</div>
		
	</div>
</template>

<script>	
	export default {
		name:"DetailHeader",	
		data:function(){
			return{
				showabs:true,
				opacityStyle:{
					opacity:0
				}
			}
		},
		methods:{
			handleScroll:function(){				
				var top  = document.documentElement.scrollTop
				if(top>60){
					var opacity = top/140;
					opacity = opacity>1?1:opacity
					this.opacityStyle = {
						opacity
					}
					this.showabs = false
				}else{
					this.showabs = true
				}
			}
		},
		activated:function(){
			window.addEventListener('scroll',this.handleScroll)
		},
		deactivated:function(){
			window.removeEventListener('scroll',this.handleScroll)
			//当页面消失的时候解绑事件
		}
	}
</script>

<style lang="stylus" scoped>
	@import '~styles/varibles.styl'
	.header-abs {
		position: absolute;
		left: .2rem;
		top: .2rem;
		width: .6rem;
		line-height: .6rem;
		height: .6rem;
		border-radius: .4rem;
		text-align: center;
		background: rgba(0,0,0,.8);
	}
	.header-abs-back {
		color: #fff;
		font-size: .3rem;
	}
	.header-fixed{
		z-index: 99;
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		overflow: hidden;
		height: $headerHeight;
		line-height: $headerHeight;
		text-align: center;
		color: #fff;
		background: $bgColor;
		font-size: .32rem;		
	}
	.header-fixed-back {
		position: absolute;
		left: 0;
		top: 0;
		width: 0.64rem;
		color: #fff;
	}
</style>